package com.mmy.dao.oa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.oa.LeaveInfo;

public interface LeaveInfoRepository extends JpaRepository<LeaveInfo, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iLeaveID) from tSysLeaveInfo", nativeQuery = true)
	Object getMaxLeaveID();

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tSysLeaveInfo where tSysLeaveInfo.iLeaveID in (:lstLeaveID)", nativeQuery = true)
	void delLeaveInfo(@Param("lstLeaveID") List<Integer> lstLeaveID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tSysLeaveInfo where iLeaveID = :iLeaveID", nativeQuery = true)
	LeaveInfo findByLeaveID(@Param("iLeaveID") int iLeaveID);


	/*
	 * 新增id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tSysLeaveInfo(iLeaveID, iUserID, cReason, iTypeID, dStart, dEnd, iDay, iState, iFlag, iMrgID, dConfirm, cMessage, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:leaveID, 0, NULL, 0, NULL, NULL, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("leaveID") int leaveID);

}
